<?php
namespace app\admin\controller;
use think\Db;
class Fight extends Common{
    public function index()
    {
        if(request()->isPost()){
            $key=input('post.key');
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('pageSize');
            $list=db('team_fight')
                ->alias('u')
                ->field('u.*')
                ->where('u.team_a','like',"%".$key."%")
                ->order('u.id desc')
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
            $team = DB::name('team')->select();

            foreach($list['data'] as $k =>$v){
                $list['data'][$k]['fight_time'] = date("Y-m-d H:i:s",$v['fight_time']);
                $list['data'][$k]['team_a'] = $team[ $list['data'][$k]['team_a'] ]['name'];
                $list['data'][$k]['team_b'] = $team[ $list['data'][$k]['team_b'] ]['name'];
                $result_arr = [0=>'结果未知',1=> $list['data'][$k]['team_a'].'胜利',2=> $list['data'][$k]['team_b'].'胜利'];
                $list['data'][$k]['result'] = $result_arr[$list['data'][$k]['result']];
                $status_arr = [0=>'比赛未开始',1=>'比赛进行中',2=>'比赛已结束'];
                $list['data'][$k]['status'] = $status_arr[$list['data'][$k]['status']];
            }
            return $result = ['code'=>0,'msg'=>'获取成功!','data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
        }
        return $this->fetch();
    }




}